﻿<Window x:Class="SmartMeterParamSetting.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:x1="clr-namespace:SmartMeterParamSetting"
        Title="智能电能表参数校对及费控功能测试软件" Height="768" Width="1024" WindowState="Maximized" Icon="image\icon.ico">
    <Window.Resources>
        <x1:ConverterMeterState x:Key="meterState"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
            <RowDefinition Height="26"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" >
            <ToolBar Name="Tool_Buttons">
                <Button Name="Btn_System" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Setting.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="系统设置" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Separator/>
                <Button Name="Btn_Import" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Import.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="方案导入" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Name="Btn_DataView" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Import.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="数据视图" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Name="Btn_Clear" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Clear.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="数据清理" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Separator/>
                <ToggleButton Name="Btn_FeiKong" Style="{DynamicResource ToolBarToggleBtn}" Click="ToolTogBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/feikong.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="费控项目" VerticalAlignment="Center"/>
                    </StackPanel>
                </ToggleButton>
                <Separator/>
                <ToggleButton Name="Btn_Star" Style="{DynamicResource ToolBarToggleBtn}" Click="ToolTogBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Start.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="开    始" VerticalAlignment="Center"/>
                    </StackPanel>
                </ToggleButton>
                <Button Name="Btn_Stop" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Stop.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="停    止" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Name="Btn_Close" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/Close.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="关    闭" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Separator/>
                <Button Name="Btn_About" Style="{DynamicResource ToolBarButton}" Click="ToolBtn_Click">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/image/About.png" Opacity="0.75" Width="32" Height="32"/>
                        <TextBlock Text="关    于" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
            </ToolBar>
            
            <ToolBar Name="Tool_FeiKong" Visibility="Collapsed" Height="30">
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="拉    闸" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="合    闸" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="报    警" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="取消报警" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="保    电" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="解除保电" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
                <Button Margin="0,0,5,1" Style="{DynamicResource ToolBarButton}" Click="Btn_FeiKong_Click" Height="24">
                    <StackPanel Orientation="Horizontal">
                        <Path Margin="0,3,0,0" Style="{StaticResource Triangle}"/>
                        <TextBlock Margin="5,0,2,0" Text="密钥下装" VerticalAlignment="Center"/>
                    </StackPanel>
                </Button>
            </ToolBar>
        </StackPanel>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition  Width="20*"/>
                <ColumnDefinition Width="80*"/>
            </Grid.ColumnDefinitions>
            <TabControl Margin="10" Effect="{DynamicResource Normal}">
                <TabItem Header="项目列表" Style="{DynamicResource TabItemStyle1}" Name="tiFaItems">
                    <ListBox  Name="Lst_PrjItems" 
                              HorizontalAlignment="Stretch" 
                              BorderBrush="{DynamicResource selectedStroke}" 
                              FontSize="13.333" 
                              Background="#FFF0F0F0" DisplayMemberPath="PrjName"
                              MouseLeftButtonUp="Lst_PrjItems_MouseLeftButtonUp"
                              >
                    </ListBox>
                </TabItem>
            </TabControl>
            <GridSplitter Margin="0,10,0,10" Width="2" ResizeDirection="Columns" Grid.Column="0" HorizontalContentAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" />
            <Grid Grid.Column="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TabControl Margin="10" Grid.Row="0" Effect="{DynamicResource Normal}">
                    <TabItem Header="表状态" Style="{DynamicResource TabItemStyle1}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>
                            <ListBox MinHeight="30" 
                                     Name="LstMeterState" 
                                     BorderBrush="{DynamicResource selectedStroke}" 
                                     Background="#FFF0F0F0" 
                                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                     ScrollViewer.VerticalScrollBarVisibility="Disabled" 
                                     IsTextSearchEnabled="False" 
                                     SelectionMode="Extended" Style="{x:Null}"  >
                                <ListBox.ItemContainerStyle>
                                    <Style TargetType="ListBoxItem">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ListBoxItem">
                                                    <Border Margin="2" CornerRadius="4,4,4,4" BorderThickness="1" BorderBrush="White" >
                                                        <ContentPresenter/>
                                                    </Border>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                                <ListBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel/>
                                    </ItemsPanelTemplate>
                                </ListBox.ItemsPanel>
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0" Margin="2,0,2,0"  FontSize="12" FontFamily="宋体" FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Path=MeterBwh,StringFormat={}{0:D2}}"/>
                                            <Image Grid.Column="1" Margin="4,2,4,2" 
                                                   Source="{Binding Path=CurrentState,Converter={StaticResource meterState},ConverterParameter=Image/NoCheck.png|Image/Yellow.png|Image/Red.png|Image/Green.png}" 
                                                   Width="20" Height="20"/>
                                        </Grid>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Border Grid.Row="1" Margin="0,2,0,0" Background="#FFFFFFFF" BorderThickness="1" BorderBrush="{DynamicResource selectedStroke}">
                                <Border Background="#FFF0F0F0" Margin="1" BorderBrush="#FFF0F0F0" BorderThickness="1">
                                    <StackPanel  Margin="0,0,0,0" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
                                        <Image Source="Image/NoCheck.png" Width="20" Height="20" VerticalAlignment="Center" Margin="4,1,0,1"/>
                                        <TextBlock Margin="2,1,4,1" Text="- 不检" VerticalAlignment="Center"/>
                                        <Image Source="Image/Yellow.png" Width="20" Height="20" VerticalAlignment="Center" Margin="4,1,0,1"/>
                                        <TextBlock Margin="2,1,4,1" Text="- 进行" VerticalAlignment="Center"/>
                                        <Image Source="Image/Red.png" Width="20" Height="20" VerticalAlignment="Center" Margin="4,1,0,1"/>
                                        <TextBlock Margin="2,1,4,1" Text="- 失败" VerticalAlignment="Center"/>
                                        <Image Source="Image/Green.png" Width="20" Height="20" VerticalAlignment="Center" Margin="4,1,0,1"/>
                                        <TextBlock Margin="2,1,0,1" Text="- 成功" VerticalAlignment="Center"/>
                                    </StackPanel>
                                </Border>
                            </Border>
                        </Grid>
                    </TabItem>
                </TabControl>
                <TabControl Margin="10,0,10,10" Grid.Row="1" Effect="{DynamicResource Normal}">
                    <TabItem Header="被检表信息" Style="{DynamicResource TabItemStyle1}">
                        <DataGrid Name="Data_Meter" 
                                  BorderBrush="{DynamicResource selectedStroke}" 
                                  RowHeight="24" 
                                  VerticalContentAlignment="Center" 
                                  BorderThickness="1" 
                                  RowStyle="{DynamicResource DataGridRowStyle1}" 
                                  VerticalGridLinesBrush="{DynamicResource TabControlNormalBorderBrush}" 
                                  CellStyle="{DynamicResource DataGridCellStyle1}" 
                                  HorizontalGridLinesBrush="{DynamicResource TabControlNormalBorderBrush}"  
                                  IsSynchronizedWithCurrentItem="False" 
                                  CanUserSortColumns="False" 
                                  FontSize="12" IsReadOnly="False" 
                                  AutoGenerateColumns="False" HeadersVisibility="All" 
                                  CanUserReorderColumns="False" CanUserAddRows="False" RowHeaderWidth="0"
                                  DisplayMemberPath="{Binding Path=MeterInfo}">
                            <DataGrid.ColumnHeaderStyle>
                                <Style  TargetType="DataGridColumnHeader">
                                    <Setter Property="HorizontalContentAlignment" Value="Center">
                                    </Setter>
                                </Style>
                            </DataGrid.ColumnHeaderStyle>
                            <DataGrid.Columns>
                                <DataGridTemplateColumn Width="50" CanUserResize="False" IsReadOnly="True" >
                                    <DataGridTemplateColumn.Header>
                                        <Grid Margin="-2,0,-2,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition/>
                                            </Grid.ColumnDefinitions>
                                            <CheckBox Margin="0,2,0,0" Grid.Column="0" VerticalAlignment="Center" Click="CheckBox_Click"/>
                                            <TextBlock Margin="2,0,0,0" Grid.Column="1" Text="要检"/>
                                        </Grid>
                                    </DataGridTemplateColumn.Header>
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding Path=CheckYn,Mode=TwoWay,NotifyOnSourceUpdated=True,UpdateSourceTrigger= PropertyChanged}" Click="RowCheck_Click"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="表位号" Width="45" IsReadOnly="True" CanUserResize="False">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <TextBlock  FontWeight="Bold" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Path=MeterBwh, StringFormat={}{0:D2}}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Width="110" Header="通信地址" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Path=MeterAddress}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <!--<DataGridTemplateColumn Header="当前项目" Width="25*" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid >
                                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Path=CurrentPrjName}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>-->
                                <DataGridTemplateColumn Header="当前状态" Width="75*" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid >
                                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Path=CurrentDesc}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="设置结果" Width="60" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid >
                                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Path=CurrentSetResult}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                                <DataGridTemplateColumn Header="复核结果" Width="60" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Grid >
                                                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Path=CurrentCheckResult}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                            </DataGrid.Columns>
                        </DataGrid>
                    </TabItem>
                </TabControl>
            </Grid>
        </Grid>
        <StatusBar Grid.Row="2" Height="26"  Name="statusBar1" VerticalAlignment="Top">
            <Grid Width="{Binding ElementName=statusBar1,Path=ActualWidth}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
            <Button Grid.Column="0" Name="Btn_LinkDevice" Padding="-2" Style="{DynamicResource ToolBarButton}" HorizontalAlignment="Left" Margin="5,1,2,0" Click="Btn_LinkDevice_Click">装置联机:</Button>
            <TextBlock Grid.Column="1" Name="Txt_SET" HorizontalAlignment="Left" Margin="0,2,2,2" Width="60">正常</TextBlock>
            <Button Grid.Column="2" Padding="-2" Name="Btn_LinkMachine" Style="{DynamicResource ToolBarButton}" HorizontalAlignment="Left" Margin="2,1,0,0" Click="Btn_LinkMachine_Click" >加密机联机：</Button>
            <TextBlock Grid.Column="3" Name="Txt_Machine" HorizontalAlignment="Left" Margin="0,2,2,2" Width="60">正常</TextBlock>
                <TextBlock Grid.Column="4" Text="Copyright ©  2012 Winahriman's Studio" HorizontalAlignment="Right" Margin="0,2,12,2"/>
            </Grid>
        </StatusBar>
        
    </Grid>
</Window>
